<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="com.cinsea.common.*" %>
<%@ page import="com.cinsea.util.*" %>
<%@ page import="com.cinsea.settings.service.GlobalsettingService" %>
<%@ page import="com.cinsea.security.service.UserService" %>
<%@ page import="com.cinsea.security.model.User" %>
<%@ page import="java.util.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<%
    Locale locale = request.getLocale();
    String languge = locale.toString();

    GlobalsettingService globalsettingService = (GlobalsettingService) Env.getBean("globalsettingService");
    String verifycode = StringUtil.null2String(globalsettingService.getSetting("37").getObjvalue());
    String sysid = StringUtil.null2String(request.getParameter("sysid"));
    String ispassmodel = StringUtil.null2String(request.getParameter("ispassmodel"));
    String typestr = "password";
    if (!StringUtil.isEmpty(sysid) && "1".equals(ispassmodel)) {
        typestr = "text";
    }
    UserService userService = (UserService) Env.getBean("userService");
    User sysuser = userService.get(sysid);


    String RndData = "";
    char Upper = '9';
    char Lower = '0';
    Random r = new Random();
    for (int i = 0; i < 15; i++) {
        int tempval = (int) ((int) Lower + (r.nextFloat() * ((int) (Upper - Lower))));
        RndData += new Character((char) tempval).toString();
    }
%>
<html>
<head>
    <link rel="stylesheet" type="text/css" href="../css/index.css">
    <link rel="stylesheet" type="text/css" href="${ctx}/js/ext/resources/css/ext-all.css"/>
    <script type="text/javascript" src="${ctx}/js/ext/adapter/ext/ext-base.js"></script>
    <script type="text/javascript" src="${ctx}/js/ext/ext-all.js"></script>
    <style type="text/css">
        .x-panel-btns-ct {
            padding: 0px;
        }

        .x-panel-btns-ct table {
            width: 0
        }

        #formdiv {
            background: #c3daf9;
        }

        td {
            font: 11px tahoma, arial, verdana, sans-serif;
        }
    </style>
    <script type="text/javascript">

		function pad(num, n) {
			var len = num.toString().length;
			while(len < n) {
				num = num+"&nbsp;";
				len++;
			}
			return num;
		}
        function getNewcode() {
            codeimg = document.getElementById("codeimg");
            codeimg.setAttribute("src", "${ctx}/static/captcha.do?" + Math.random())
        }
        var myMask;
        Ext.onReady(function () {
                    var nav = new Ext.KeyNav("j_password", {
                        "enter":function (e) {
                            login();
                        },
                        scope:this
                    });
                    document.getElementById('j_username').focus();
                    if (cp.get('rempwd')) {
                        document.getElementById('rempwd').checked=true;
                    }
                    if (cp.get('loginname')) {
                        document.getElementById('idPlaceholder').innerHTML = '';
                        document.getElementById('j_username').value = cp.get('loginname');
                        document.getElementById('j_password').focus();
                    }
                    if (cp.get('loginpwd')) {
                        document.getElementById('pwdPlaceholder').innerHTML = '';
                        document.getElementById('j_password').value = cp.get('loginpwd');
                        document.getElementById('j_password').focus();
                    }
                }
        );

        var cp = new Ext.state.CookieProvider({
            expires: new Date(new Date().getTime() + (1000 * 60 * 60 * 24 * 30))
        });

        function login() {
            myMask = new Ext.LoadMask(Ext.getBody(), {msg:'<%=I18n.getText("wait",languge)%>'});
            document.getElementById("isusb").value = "";
            if (document.getElementById('rempwd').checked) {
                cp.set('rempwd', 1);
                cp.set('loginname', document.getElementById('j_username').value);
                cp.set('loginpwd', document.getElementById('j_password').value);
            }
            else {
                cp.set('rempwd', 0);
                cp.set('loginpwd', '');
            }
            myMask.show();
            Ext.Ajax.request({
                form:form1,
                success:function (res) {
                    var responsetext = res.responseText;
                    if (res.responseText == 'success') {
                        location.replace('${ctx}/main/main.jsp');
                    }
                    else if (responsetext == 'failurepass') {

                        Ext.Msg.alert('', '<%=I18n.getText("dynapass",languge)%><%=I18n.getText("error",languge)%>！');
                        myMask.hide();
                    }
                    else if (responsetext == 'failure') {

                        myMask.hide();
                        Ext.Msg.alert('', '<%=I18n.getText("00010",languge)%>');

                    } else {
                        location.replace('${ctx}/main/login.jsp?' + responsetext);
                    }
                }
            });
        }

    </script>
</head>
<body style="padding-top: 5px;">
<div class="header">
    <!--h1 class="headerLogo"><img src="../images/face/com.png"/></h1-->
	<span class="headerLogo"><a></a></span>
	<span class="headerNav"><a></a></span>
</div>


<div style="background: none repeat scroll 0% 0% transparent;" class="main" id="mainBg">
    <div style="background-image: url('../images/face/loginbg.jpg'); background-repeat: no-repeat; background-position: center top;"
         class="main-inner" id="mainCnt">
        <div id="theme">

            <div id="themeArea">
                <div id="themeAreaInner"></div>
            </div>

        </div>
        <div id="loginBlock" class="login tab-1" style="background-color:transparent;border-color:transparent;margin-top: 164px;margin-right: 295px">
            <div class="loginForm">
                <form name="form1" method="post" action="${ctx}/j_spring_security_check" onsubmit="return false">
                    <input type='hidden' id="rndData" name="rndData" Value="<%=RndData%>">
                    <input type='hidden' id="encData" name="encData" Value="">
                    <input type='hidden' id="isusb" name="isusb" Value="">
                    <%if (!StringUtil.isEmpty(sysid)) {%>
                    <input type="hidden" name="sendpass" value="1">
                    <input type="hidden" name="sysid" value="<%=sysid%>">
                    <%}%>

                    <div id="idInputLine" class="loginFormIpt showPlaceholder" style="margin-top: 32px;">
                        <input class="loginFormTdIpt" tabindex="1" id="j_username" name="j_username" tabindex="1"
                               <%if(!StringUtil.isEmpty(sysuser.getUsername())){%>value="<%=sysuser.getUsername()%>"
                               readonly="true"
                               style="background-color: graytext;"<%}%>
                               maxlength="50" value="" type="text" onkeypress="document.getElementById('idPlaceholder').innerHTML='';" onblur="if(this.value==''){document.getElementById('idPlaceholder').innerHTML='<%=I18n.getText("account", languge)%>'}" >

                        <div id="mobtips" style=""></div>
                        <%if(StringUtil.isEmpty(sysuser.getUsername())){%>
                        <label for="idInput" class="placeholder"
                               id="idPlaceholder" onclick="document.getElementById('j_username').focus()"><%=I18n.getText("account", languge)%></label>
                        <%}%>
                    </div>
                    <div class="newLine">
                    </div>
				
                    <div id="pwdInputLine" class="loginFormIpt showPlaceholder">
                        <input class="loginFormTdIpt" tabindex="2" type="<%=typestr%>" id="j_password"
                               name="j_password" onkeypress="document.getElementById('pwdPlaceholder').innerHTML='';" onblur="if(this.value==''){document.getElementById('pwdPlaceholder').innerHTML='<%=I18n.getText("password", languge)%>'}" >
                        <label for="pwdInput" class="placeholder"
                               id="pwdPlaceholder" onclick="document.getElementById('j_password').focus()"><%=I18n.getText("password", languge)%>
                        </label>
                    </div>
                    <div class="loginFormCheck">
                        <input tabindex="3"  class="loginFormCbx" type="checkbox" id="rempwd" /><label id="remAutoLoginTxt" class="loginFormSslText" for="rempwd">&nbsp;记住密码&nbsp;</label>
                    </div>
                    <%if (verifycode.equals("1")) {%>
                    <div class="loginFormCheck">
                        <span><%=I18n.getText("verifycode", languge)%> :

                                    <input type="text" name="verifycode" size="4" tabindex="3"
                                           style="width:50px"/>
                                    <img id="codeimg" src='${ctx}/static/captcha.do' onclick="getNewcode()" style="vertical-align: bottom;"></span>

                    </div>
                    <%}%>

                    <div class="loginFormIpt loginFormIptWiotTh">
                        <button id="loginBtn" name="loginBtn" class="btn btn-login formSubmit" tabindex="6" type="button" onclick="login()" onmouseover="document.getElementById('loginBtn').className += ' btn-login-hover'" onmouseout="document.getElementById('loginBtn').className = 'btn btn-login'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%=I18n.getText("login", languge)%>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>


<div style="background: none repeat scroll 0% 0% transparent;" id="footer" class="footer">
    <div style="background: none repeat scroll 0% 0% transparent;" class="footer-inner" id="footerInner">
        <nav class="footerNav">
            <span class="footerLogo">提示：建议使用IE8.0浏览器，分辨率1280*800
            </span>
        </nav>
    </div>
</div>
</body>
</html>
